package com.xihuanjun.healthcode.controller;

import com.xihuanjun.healthcode.entity.AllTypes;
import com.xihuanjun.healthcode.exception.ServiceException;
import com.xihuanjun.util.MapUtils;
import com.xihuanjun.util.json.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author: 江溪浣
 * @createDate: 2022/10/25 13:50
 * @description:
 */
@RequestMapping("/type")
@RestController
public class TypeController {

    @Autowired
    AllTypes allTypes;

    @GetMapping("/list/card")
    public JsonResult getCardTypes(){
        return new JsonResult().code(200).data(JsonResult.KEY_ITEMS, MapUtils.toList(AllTypes.cardType));
    }


    @GetMapping("/list/person/{changeType}")
    public JsonResult getPersonTypes(@PathVariable("changeType") int changeType){
        List<Map<String, Object>> maps=null;
        switch (changeType){
            case 1:
                maps= MapUtils.toList(AllTypes.personType1);
                break;
            case 2:
                maps= MapUtils.toList(AllTypes.personType2);
                break;
            case 3:
                maps= MapUtils.toList(AllTypes.personType3);
                break;
                default:
                    throw new ServiceException("赋码类型错误");
        }

        return new JsonResult().code(200).data(JsonResult.KEY_ITEMS, maps);
    }
}
